GdPicture.NET.14
GdPicture14 Namespace / GdViewer Class / SearchTextRegex Method / SearchTextRegex(Int32,String,Int32,Boolean,IEnumerable<RectangleF>) Method
The number of the page to search for text. It must be a value from 1 to the value of the PageCount property.
The textregular expression pattern to search for.
The occurrence of the searched expression on the required page. Set the occurrence to 1 if you are searching for the first occurrence, set it to 2 for the second etc.

The value of 0 is not accepted, it will always be converted to 1. Please note that the occurrence is always related to the specified page.

Set this parameter to true if you want to apply case-sensitive search, otherwise set it to false.
Output parameter. If the searched expression has been found, this is the list of bounding box rectangle definined in inches.
Example





In This Topic
SearchTextRegex(Int32,String,Int32,Boolean,IEnumerable<RectangleF>) Method
In This Topic
Searches for an occurrence of a given regular expression pattern within the defined page of the document displayed in the GdViewer control according to the parameters you have specified. This method returns the bounding boxes (rectangle) surrounding the searched expression on the required page defined by its top left coordinates and by its width and height in inches, if the expression has been found. This occurrence is not highlighted using this method.

Be aware that this method uses InvariantCulture comparison when searching. It means, that characters are comparing using culture-sensitive sort rules and the invariant culture, in other words this method respects accents when searching.

Syntax
'Declaration
 
Public Overloads Function SearchTextRegex( _
   ByVal Page As Integer, _
   ByVal Pattern As String, _
   ByVal Occurence As Integer, _
   ByVal CaseSensitive As Boolean, _
   ByRef BoundingArray As IEnumerable(Of RectangleF) _
) As Boolean
public bool SearchTextRegex( 
   int Page,
   string Pattern,
   int Occurence,
   bool CaseSensitive,
   out IEnumerable<RectangleF> BoundingArray
)
public function SearchTextRegex( 
    Page: Integer;
    Pattern: String;
    Occurence: Integer;
    CaseSensitive: Boolean;
   Out  BoundingArray: IEnumerable
): Boolean; 
public function SearchTextRegex( 
   Page : int,
   Pattern : String,
   Occurence : int,
   CaseSensitive : boolean,
   BoundingArray : IEnumerable
) : boolean;
public: bool SearchTextRegex( 
   int Page,
   string* Pattern,
   int Occurence,
   bool CaseSensitive,
   [PARAMFLAG::Out] IEnumerable<RectangleF>* BoundingArray
) 
public:
bool SearchTextRegex( 
   int Page,
   String^ Pattern,
   int Occurence,
   bool CaseSensitive,
   [Out] IEnumerable<RectangleF>^ BoundingArray
) 

Parameters

Page
The number of the page to search for text. It must be a value from 1 to the value of the PageCount property.
Pattern
The textregular expression pattern to search for.
Occurence
The occurrence of the searched expression on the required page. Set the occurrence to 1 if you are searching for the first occurrence, set it to 2 for the second etc.

The value of 0 is not accepted, it will always be converted to 1. Please note that the occurrence is always related to the specified page.

CaseSensitive
Set this parameter to true if you want to apply case-sensitive search, otherwise set it to false.
BoundingArray
Output parameter. If the searched expression has been found, this is the list of bounding box rectangle definined in inches.

Return Value

true if the given text expression has been found on the required page according to the specified parameters, otherwise false. The GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only useful for text-based document formats, like DOCX, TXT, RTF and PDF.

Just to inform you, that this method does not change the currently determined highlighted regions or the currently defined rectangle of selection. At the same, the found occurrence of the given text is not highlighted using this method.

Example
How to search for given text within the current page using different parameters.
//We assume that the GdViewer1 control has been properly integrated.
if (GdViewer1.DisplayFromFile("") == GdPictureStatus.OK)
{
    string text_to_find = "GdPicture";
    GdViewer1.RemoveAllRegions();
    bool text_found = GdViewer1.SearchText(text_to_find, 1, true, out IEnumerable<RectangleF> boundingArray);
    if (GdViewer1.GetStat() == GdPictureStatus.OK)
    {
        if (text_found)
        {
            GdViewer1.Redraw();
            MessageBox.Show("The number of highlighted regions: " + GdViewer1.RegionCount().ToString(), "GdViewer.SearchText");
        }
        else
            MessageBox.Show("The given text has not been found.", "GdViewer.SearchText");
    }
    else
        MessageBox.Show("The search process has failed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText");
}
else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.SearchText");
See Also